/*  
Creates table 2 in paper. Estimates of the relationship between image uploads and building beauty: OLS and PCF estimates


Requires the clean dataset:
${project}/clean_data/survey_level_data.dta

Arianna Salazar Miranda
*/

clear all
global project "/Users/arianna/Dropbox (MIT)/emporis_project/paper/submission_PLOS/data_repository"

**************************************************************************************************
*open survey database
**************************************************************************************************

use "${project}/Data/survey_level_data.dta", clear


**************************************************************************************************
*cleaning
**************************************************************************************************


drop if officialname=="Mark Twain Building"
drop if officialname=="Empire State Building"
drop if officialname=="Byrd's Lofts"

*Tag duplicate buildings
bysort buildingnumberebn: gen tag_unique=(_n==_N)


**************************************************************************************************
*generate donut variable*
**************************************************************************************************

*for panoramio*
gen r0_r50_picData_2014 = (r50_count_picData_2014)/10
gen r50_r100_picData_2014 = (r100_count_picData_2014 - r50_count_picData_2014)/10
gen r100_r250_picData_2014 = (r250_count_picData_2014 - r100_count_picData_2014)/10
gen r250_r500_picData_2014 = (r500_count_picData_2014 - r250_count_picData_2014)/10


*for flickr*
gen r0_r50_picData_flickr = (r50_count_picData_flickr)/10
gen r50_r100_picData_flickr = (r100_count_picData_flickr - r50_count_picData_flickr)/10
gen r100_r250_picData_flickr = (r250_count_picData_flickr - r100_count_picData_flickr)/10
gen r250_r500_picData_flickr = (r500_count_picData_flickr - r250_count_picData_flickr)/10

*generate pcf*
factor  r0_r50_picData_flickr r0_r50_picData_2014, pcf factors(1)
predict r0_r50_pcf

factor r50_r100_picData_flickr r50_r100_picData_2014, pcf factors(1)
predict r50_r100_pcf

factor r100_r250_picData_flickr r100_r250_picData_2014, pcf factors(1)
predict r100_r250_pcf

factor r250_r500_picData_flickr r250_r500_picData_2014, pcf factors(1)
predict r250_r500_pcf


**************************************************************************************************
*generate new variables for tables
**************************************************************************************************
egen st_sid=group(session_id)
bysort buildingnumberebn: egen score_mean=mean(score)
bysort buildingnumberebn: egen count_building=count(score)

foreach depvar in picData_2014 picData_flickr pcf {

**************************************************************************************************
*TABLE 2*
**************************************************************************************************

******************************
* 1) Baseline (photos within 0-50 meters)*
******************************
reg score r0_r50_`depvar', cluster(buildingnumberebn)

******************************
* 2) Session effects*
******************************
areg score r0_r50_`depvar', a(session_id) cluster(buildingnumberebn)

******************************
* 3) Photo count effects*
******************************
areg score r0_r50_`depvar' i.photo_count, a(session_id) cluster(buildingnumberebn)

******************************
* 4) consistency weighting*
******************************
areg score r0_r50_`depvar' i.photo_count [w=inc_w_dif], a(session_id) cluster(buildingnumberebn)

******************************
* 5) decay with all controls*
******************************
areg score r0_r50_`depvar' r50_r100_`depvar' r100_r250_`depvar' r250_r500_`depvar' i.photo_count,  a(session_id) cluster(buildingnumberebn)


}









